
struct AVLNode {
  struct AVLNode * left;
  struct AVLNode * right;
  void * key;
  void * data;
};

struct AVLTree {
  int size;
  AVLNode * root;
};

void * Malloc( size_t size ) {
  void * toReturn = malloc(size);
  if (! toReturn ) {
    perror("malloc: ");
    exit(1);
  }
  return toReturn;
}

struct AVLNode * insertInSubtree ( struct AVLTree * tree, struct AVLNode * current, 
				   void * key, void * value ) {

  if ( current == NULL ) {
    tree->size ++;
    return Malloc(sizeof(struct AVLNode));
  }
  
  if ( current->key == key ) {
    current -> value = value;
  }
  else if ( current->key > key ) {
    current->left = insertInSubtree(tree, current->left, key, value);
    // TODO - balance function
  }
  else {
    current->right = insertInSubtree(tree, current->right, key, value);
    // TODO - balance function
  }
  return current;
}


    
